package ahblue.cn.tanzi.model.user;

import android.content.Context;
import android.widget.Toast;

import java.util.List;

import ahblue.cn.tanzi.data.source.ApiCallback;
import ahblue.cn.tanzi.data.source.RemoteRepository;
import ahblue.cn.tanzi.jmessage.im.util.ToastUtil;
import ahblue.cn.tanzi.model.home.VideoModel;
import ahblue.cn.tanzi.util.PinkJSON;

/**
 * @author pink-jackstraw
 * @date 2018/11/10
 * @describe
 */
public class CodeModel {

    public String order_sn;
    public String url;

    public static void updatePhone(final Context context , String member_mobile, final CodeListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.updatePhone(member_mobile, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver();
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver();
                }
            }
        });
    }
    public static void getLoginCode(final Context context , String member_mobile, final CodeListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getLoginCode(member_mobile, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver();
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver();
                }
            }
        });
    }

    /**
     * 注册获取邀请码
     * @param context
     * @param member_mobile
     * @param loginListener
     */
    public static void getRegistCode(final Context context , String member_mobile,String invite_code, final CodeListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getRegistCode(member_mobile,invite_code, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver();
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver();
                }
            }
        });
    }

    public static void getPayMoney(final Context context , String recharge_amount,String token, final VertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getMoney(recharge_amount,token, new ApiCallback<String>(){
            @Override
            public void onSuccess(String data) {
                Toast.makeText(context,data,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }

    public static void getOrderPayNo(final Context context , String recharge_amount,String token, final DataVertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getOrderPayNo(recharge_amount,token, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(data.order_sn);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver("");
                }
            }
        });
    }

    public static void getVipOrderPayNo(final Context context , String token,String viptype, final DataVertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getVipOrderPayNo(token,viptype, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(data.order_sn);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver("");
                }
            }
        });
    }

    public static void inviteRealCode(final Context context ,
                                      String token,
                                      String bank_card,
                                      String banalipay_account,
                                      String identity_card,
                                      String member_name,
                                      final VertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.inviteRealCode(member_name,bank_card,banalipay_account,identity_card,token, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }


    public static void setProfit(final Context context ,
                                      String profile,
                                      String token,
                                      final DataVertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.setProfit(profile,token, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                ToastUtil.shortToast(context,"操作成功");
                if (null!=loginListener){
                    loginListener.conver(profile);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver("");
                }
            }
        });
    }


    public static void setNiceName(final Context context ,
                                      String profile,
                                      String token,
                                      final VertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.setNickName(profile,token, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }

    public static void loginOut(final Context context ,
                                      String token,
                                      final VertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.loginOut(token, new ApiCallback<String>(){
            @Override
            public void onSuccess(String data) {
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }


    public static void BindRegid(final Context context ,
                                String regid,String token,
                                final VertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.BindRegid(token,regid, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }

    public static void ShareLink(final Context context ,String token,
                                final DataVertifyListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.ShareLink(token, new ApiCallback<CodeModel>(){
            @Override
            public void onSuccess(CodeModel data) {
                if (null!=loginListener){
                    loginListener.conver(data.url);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver("");
                }
            }
        });
    }


    public static void CommentVideo(final Context context ,String comment_type,String id,
                                String content,String token,
                                final SuccessListener loginListener){
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.CommentVideo(comment_type,id,content,token, new ApiCallback<List<CodeModel>>(){
            @Override
            public void onSuccess(List<CodeModel> data) {
                Toast.makeText(context,"评论成功！",Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(true);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context,errorMsg,Toast.LENGTH_LONG).show();
                if (null!=loginListener){
                    loginListener.conver(false);
                }
            }
        });
    }

    public interface CodeListener {
        void conver();
    }

    public interface SuccessListener {
        void conver(boolean b);
    }

    public interface VertifyListener {
        void conver(boolean b);
    }

    public interface DataVertifyListener {
        void conver(String orderSn);
    }


}
